#! /usr/bin/env python3

import pytest
import logging
from selenium import webdriver

from keywords import UiKeyWords, ApiKeyWords


@pytest.fixture(scope='function')
def driver():
    """前置与后置操作"""
    driver = webdriver.Safari()
    driver.implicitly_wait(5)
    yield driver
    driver.quit()


@pytest.fixture(scope='session', autouse=True)
def logger():
    logger = logging.getLogger('test')
    logger.setLevel(logging.DEBUG)
    file_handler = logging.FileHandler(
        filename='run.log', mode='a', encoding='utf-8')
    file_handler.setLevel(logging.DEBUG)
    formater = logging.Formatter(
        '%(asctime)s --> %(levelname)6s --> %(message)s')
    file_handler.setFormatter(formater)
    logger.addHandler(file_handler)
    yield logger


@pytest.fixture(scope='function')
def keyword(driver):
    kw = UiKeyWords(driver)
    yield kw
